package linwen.wang.tdddemo.repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import linwen.wang.tdddemo.entity.UserInfoEntity;
import linwen.wang.tdddemo.mapper.UserInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class UserRepository {
    @Autowired
    private UserInfoMapper userInfoMapper;

    public UserInfoEntity getUserInfo(Long id) {
        return userInfoMapper.selectById(id);
    }

    public void save(UserInfoEntity userInfoEntity) {
        userInfoMapper.insert(userInfoEntity);
    }

    // 分页查询,例：每页两条记录，查询第一页
    public void testCommonSelect() {
        UserInfoEntity userInfoEntity = new UserInfoEntity();
        userInfoEntity.setId(11l);
        QueryWrapper<UserInfoEntity> ew = new QueryWrapper<UserInfoEntity>();
        ew.setEntity(userInfoEntity);
        IPage<UserInfoEntity> userInfoEntityIPage = userInfoMapper.selectPage(new Page<>(1, 2), ew);
        List<UserInfoEntity> records = userInfoEntityIPage.getRecords();
    }

}
